//
//  MTRedpackMoreView.swift
//  MT
//
//  Created by ooops on 2019/12/25.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import YHPopupView

@objc protocol MTRedpackMoreViewDelegate: NSObjectProtocol {
    @objc optional func popupView(view: MTRedpackMoreView, send addButton: UIButton)
    @objc optional func popupView(view: MTRedpackMoreView, recive addButton: UIButton)
}

class MTRedpackMoreView: YHPopupView {

    weak var delegate: MTRedpackMoreViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        _init()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var sendBtn: UIButton = {
        var send = UIButton()
        send.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        send.addTarget(self, action: #selector(sendAction), for: .touchUpInside)
        send.setTitle("我收到的", for: .normal)
        send.backgroundColor = .white
        send.setTitleColor(.black, for: .normal)
        return send
    }()
    
    private lazy var reciveBtn: UIButton = {
        var recive = UIButton()
        recive.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        recive.addTarget(self, action: #selector(reciveAction), for: .touchUpInside)
        recive.setTitle("我发出的", for: .normal)
        recive.backgroundColor = .white
        recive.setTitleColor(.black, for: .normal)
        return recive
    }()
    
    lazy var bgColorView: UIView = {
        let v = UIView()
        v.backgroundColor = .white
        return v
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0xAFA2A4)
        return v
    }()
    
    private func _init() {
        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
        imageView.image = UIImage.loadImage("com_icon _selectList")
        addSubview(imageView)
        
        imageView.addSubview(bgColorView)
        bgColorView.frame = imageView.frame
        
        backgroundViewColor = .clear
        clickBlankSpaceDismiss = true
        
        let height = 38
        let width = self.width
        let image = UIImage.createImage(color: UIColor(hex: 0xFFFFFF), size: CGSize(width: 140, height: height))
        
        sendBtn.frame = CGRect(x: 0, y: 5, width: Int(width), height: height)
        reciveBtn.frame = CGRect(x: 0, y: 5 + height, width: Int(width), height: height)
    
        addSubview(sendBtn)
        addSubview(reciveBtn)
        
        addSubview(lineView)
        
        lineView.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
    }
    
    @objc private func sendAction() {
        delegate?.popupView?(view: self, send: sendBtn)
    }
    
    @objc private func reciveAction() {
        delegate?.popupView?(view: self, recive: reciveBtn)
    }
}
